package com.shangcheng.dubbo.api;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shangcheng.dubbo.mappers.PmsProductFullReductionMapper;
import com.shangcheng.model.domain.PmsMemberPrice;
import com.shangcheng.model.domain.PmsProductFullReduction;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductFullReductionApiImpl implements PmsProductFullReductionApi {
    @Autowired
    private PmsProductFullReductionMapper productFullReductionMapper;

    @Override
    public void save(List<PmsProductFullReduction> productFullReductionList, Long id) {
        if (ObjectUtil.isNotEmpty(productFullReductionList)) {
            for (PmsProductFullReduction pmsProductFullReduction : productFullReductionList) {
                pmsProductFullReduction.setProductId(id);
                productFullReductionMapper.insert(pmsProductFullReduction);
            }
        }
    }

    @Override
    public List<PmsProductFullReduction> findByProductId(Integer id) {
        return productFullReductionMapper.selectList(new LambdaQueryWrapper<PmsProductFullReduction>().eq(PmsProductFullReduction::getProductId, id));
    }

    @Override
    public void updateById(List<PmsProductFullReduction> productFullReductionList, Integer id) {
        productFullReductionMapper.delete(new LambdaQueryWrapper<PmsProductFullReduction>().eq(PmsProductFullReduction::getProductId, id));
        this.save(productFullReductionList, Convert.toLong(id));
    }
}
